package fault_file

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/fault_file"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    fault_fileReq "github.com/flipped-aurora/gin-vue-admin/server/model/fault_file/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type Fault_file_structApi struct {
}

var fault_file_structService = service.ServiceGroupApp.Fault_fileServiceGroup.Fault_file_structService


// CreateFault_file_struct 创建Fault_file_struct
// @Tags Fault_file_struct
// @Summary 创建Fault_file_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body fault_file.Fault_file_struct true "创建Fault_file_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fault_file_struct/createFault_file_struct [post]
func (fault_file_structApi *Fault_file_structApi) CreateFault_file_struct(c *gin.Context) {
	var fault_file_struct fault_file.Fault_file_struct
	err := c.ShouldBindJSON(&fault_file_struct)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "Ata_chapter_level1":{utils.NotEmpty()},
        "Ata_chapter_level2":{utils.NotEmpty()},
        "Fault_number":{utils.NotEmpty()},
    }
	if err := utils.Verify(fault_file_struct, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := fault_file_structService.CreateFault_file_struct(&fault_file_struct); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteFault_file_struct 删除Fault_file_struct
// @Tags Fault_file_struct
// @Summary 删除Fault_file_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body fault_file.Fault_file_struct true "删除Fault_file_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fault_file_struct/deleteFault_file_struct [delete]
func (fault_file_structApi *Fault_file_structApi) DeleteFault_file_struct(c *gin.Context) {
	var fault_file_struct fault_file.Fault_file_struct
	err := c.ShouldBindJSON(&fault_file_struct)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fault_file_structService.DeleteFault_file_struct(fault_file_struct); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteFault_file_structByIds 批量删除Fault_file_struct
// @Tags Fault_file_struct
// @Summary 批量删除Fault_file_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Fault_file_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /fault_file_struct/deleteFault_file_structByIds [delete]
func (fault_file_structApi *Fault_file_structApi) DeleteFault_file_structByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fault_file_structService.DeleteFault_file_structByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateFault_file_struct 更新Fault_file_struct
// @Tags Fault_file_struct
// @Summary 更新Fault_file_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body fault_file.Fault_file_struct true "更新Fault_file_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /fault_file_struct/updateFault_file_struct [put]
func (fault_file_structApi *Fault_file_structApi) UpdateFault_file_struct(c *gin.Context) {
	var fault_file_struct fault_file.Fault_file_struct
	err := c.ShouldBindJSON(&fault_file_struct)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "Ata_chapter_level1":{utils.NotEmpty()},
          "Ata_chapter_level2":{utils.NotEmpty()},
          "Fault_number":{utils.NotEmpty()},
      }
    if err := utils.Verify(fault_file_struct, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := fault_file_structService.UpdateFault_file_struct(fault_file_struct); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindFault_file_struct 用id查询Fault_file_struct
// @Tags Fault_file_struct
// @Summary 用id查询Fault_file_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query fault_file.Fault_file_struct true "用id查询Fault_file_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fault_file_struct/findFault_file_struct [get]
func (fault_file_structApi *Fault_file_structApi) FindFault_file_struct(c *gin.Context) {
	var fault_file_struct fault_file.Fault_file_struct
	err := c.ShouldBindQuery(&fault_file_struct)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if refault_file_struct, err := fault_file_structService.GetFault_file_struct(fault_file_struct.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"refault_file_struct": refault_file_struct}, c)
	}
}

// GetFault_file_structList 分页获取Fault_file_struct列表
// @Tags Fault_file_struct
// @Summary 分页获取Fault_file_struct列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query fault_fileReq.Fault_file_structSearch true "分页获取Fault_file_struct列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fault_file_struct/getFault_file_structList [get]
func (fault_file_structApi *Fault_file_structApi) GetFault_file_structList(c *gin.Context) {
	var pageInfo fault_fileReq.Fault_file_structSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fault_file_structService.GetFault_file_structInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
